package base;

import cn.hutool.core.lang.func.VoidFunc1;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

public class LambdaDemo {

    static int ss = 1;

    public static void main(String[] args) {
        List<Integer> list = Arrays.asList(1, 2, 3);
        list.forEach(n -> System.out.print(n));
        list.forEach(System.out::println);

        int factor = 2;
        list.forEach((Integer n) -> System.out.println("*" + n + "*"));
        list.forEach(n -> System.out.println("*" + n * factor + "*"));
        list.forEach(n -> System.out.println("*" + n * ss + "*"));

        for (int i = 0; i < 2; i++) {
            int finalI = i;
            //Variable used in lambda expression should be final or effectively final
            list.forEach(n -> System.out.println(n * finalI));
        }

        System.out.println("===stream===");
        List<Integer> collect = list.stream().filter(i -> i >= 2).collect(Collectors.toList());
        collect.forEach(System.out::println);

        System.out.println("===function interface===");
        FunctionInterfaceDemo demo = () -> System.out.println("interface demo");
        demo.func01();
        demo.func02();
        demo.func03();
    }
}
